﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Vega.USiteBuilder;
using SPCFMedicineInformer.DocumentTypes;
using SPCFMedicineInformer.DocumentTypes.Base;
using SPCFMedicineInformer.Members;

namespace SPCFMedicineInformer.Masterpages
{
    public partial class AdminContentPageATemplate : TemplateBase<AdminContentPage>
    {
        public static string UserId { get; set; }
        protected void Page_Init(object sender, EventArgs e)
        {
            ((umbraco.UmbracoDefault)this.Page).ValidateRequest = false;

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                var User = HttpContext.Current.User.Identity;
                var member = MemberHelper.GetMemberFromEmail(User.Name) as WebUser;
                member = member == null ? MemberHelper.GetMemberFromLoginName(User.Name) as WebUser : member;
                if (member != null)
                {
                    UserId = member.Id.ToString();
                    if (!string.IsNullOrEmpty(member.Fistname))
                        litUserName.Text = member.Fistname;
                    else
                        litUserName.Text = member.Email;
                }
            }
            else
            {
                Response.Redirect("/admin/");
            }
        
                
        }

        protected void LinkButtonLogout_Click(object sender, EventArgs e)
        {
            MemberHelper.LogoutFormsAuthentication();
            var redirecUrl = NodeLocator.GetNodesOfExactType<AdminSite>().First().Url;
            Response.Redirect(redirecUrl);
        }
    }
}